
package no.uib.fragmentation_analyzer.gui;

import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JOptionPane;
import no.uib.fragmentation_analyzer.util.Util;

/**
 * Dialog for connecting to the ms_lims database.
 *
 * @author Harald Barsnes
 */
public class DatabaseDialog extends javax.swing.JDialog {

    private FragmentationAnalyzer fragmentationAnalyzer;
    private DataSource dataSourceDialog;
    private boolean extractIdentifications;

    /**
     * Opens a new DatabaseDialog frame, and inserts stored information.
     *
     * @param dataSourceDialog a reference to the DataSource dialog
     * @param fragmentationAnalyzer
     * @param modal
     * @param extractIdentifications if true the tool starts extracting the identifications after connecting
     */
    public DatabaseDialog(DataSource dataSourceDialog,
            FragmentationAnalyzer fragmentationAnalyzer, boolean modal,
            boolean extractIdentifications) {
        super(dataSourceDialog, modal);

        this.fragmentationAnalyzer = fragmentationAnalyzer;
        this.dataSourceDialog = dataSourceDialog;
        this.extractIdentifications = extractIdentifications;

        initComponents();

        // insert stored information
        userNameJTextField.setText(fragmentationAnalyzer.getUserProperties().getUserName());
        passordJPasswordField.setText(fragmentationAnalyzer.getProperties().getPassWord());
        serverHostJTextField.setText(fragmentationAnalyzer.getUserProperties().getServerHost());
        schemaJTextField.setText(fragmentationAnalyzer.getUserProperties().getSchema());

        // see if the next button should be enabled
        mandatoryFieldsCheck();

        if(userNameJTextField.getText().length() > 0){
            passordJPasswordField.requestFocus();
        }

        setLocationRelativeTo(dataSourceDialog);
        setVisible(true);
    }

    /**
     * Opens a new DatabaseDialog frame, and inserts stored information.
     *
     * @param fragmentationAnalyzer
     * @param modal
     */
    public DatabaseDialog(FragmentationAnalyzer fragmentationAnalyzer, boolean modal) {
        super(fragmentationAnalyzer, modal);

        this.fragmentationAnalyzer = fragmentationAnalyzer;
        this.extractIdentifications = false;
        dataSourceDialog = null;

        initComponents();

        // insert stored information
        userNameJTextField.setText(fragmentationAnalyzer.getUserProperties().getUserName());
        passordJPasswordField.setText(fragmentationAnalyzer.getProperties().getPassWord());
        serverHostJTextField.setText(fragmentationAnalyzer.getUserProperties().getServerHost());
        schemaJTextField.setText(fragmentationAnalyzer.getUserProperties().getSchema());

        // see if the next button should be enabled
        mandatoryFieldsCheck();

        if(userNameJTextField.getText().length() > 0){
            passordJPasswordField.requestFocus();
        }

        setLocationRelativeTo(fragmentationAnalyzer);
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jXTaskPane1 = new org.jdesktop.swingx.JXTaskPane();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        passordJPasswordField = new javax.swing.JPasswordField();
        userNameJTextField = new javax.swing.JTextField();
        jXTaskPane2 = new org.jdesktop.swingx.JXTaskPane();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        schemaJTextField = new javax.swing.JTextField();
        serverHostJTextField = new javax.swing.JTextField();
        jXPanel3 = new org.jdesktop.swingx.JXPanel();
        okJButton = new javax.swing.JButton();
        cancelJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Database Details");
        setResizable(false);

        jXTaskPaneContainer1.setOpaque(false);

        jXTaskPane1.setTitle("Login");
        jXTaskPane1.setEnabled(false);

        jXPanel1.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));

        jLabel1.setText("Username:");
        jLabel1.setToolTipText("Username to access the ms_lims database");

        jLabel2.setText("Password:");
        jLabel2.setToolTipText("Password to access the ms_lims database");

        passordJPasswordField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        passordJPasswordField.setToolTipText("Password to access the ms_lims database");
        passordJPasswordField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                passordJPasswordFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                passordJPasswordFieldKeyReleased(evt);
            }
        });

        userNameJTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        userNameJTextField.setToolTipText("Username to access the ms_lims database");
        userNameJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                userNameJTextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                userNameJTextFieldKeyReleased(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jXPanel1Layout = new org.jdesktop.layout.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2))
                .add(32, 32, 32)
                .add(jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(userNameJTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                    .add(passordJPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXPanel1Layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(userNameJTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jXPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(passordJPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jXTaskPane1Layout = new org.jdesktop.layout.GroupLayout(jXTaskPane1.getContentPane());
        jXTaskPane1.getContentPane().setLayout(jXTaskPane1Layout);
        jXTaskPane1Layout.setHorizontalGroup(
            jXTaskPane1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPane1Layout.createSequentialGroup()
                .add(jXPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
        );
        jXTaskPane1Layout.setVerticalGroup(
            jXTaskPane1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPane1Layout.createSequentialGroup()
                .add(jXPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXTaskPaneContainer1.add(jXTaskPane1);

        jXTaskPane2.setTitle("Database");

        jXPanel2.setBackground(javax.swing.UIManager.getDefaults().getColor("tab_focus_fill_dark"));

        jLabel4.setText("Server Host:");
        jLabel4.setToolTipText("The host where the ms_lims database is located");

        jLabel5.setText("Schema:");
        jLabel5.setToolTipText("The schema/table name used by ms_lims");

        schemaJTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        schemaJTextField.setToolTipText("The schema/table name used by ms_lims");
        schemaJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                schemaJTextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                schemaJTextFieldKeyReleased(evt);
            }
        });

        serverHostJTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        serverHostJTextField.setToolTipText("The host where the ms_lims database is located");
        serverHostJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                serverHostJTextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                serverHostJTextFieldKeyReleased(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jXPanel2Layout = new org.jdesktop.layout.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel4)
                    .add(jLabel5))
                .add(25, 25, 25)
                .add(jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(serverHostJTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                    .add(schemaJTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)))
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXPanel2Layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(serverHostJTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jXPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(schemaJTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jXTaskPane2Layout = new org.jdesktop.layout.GroupLayout(jXTaskPane2.getContentPane());
        jXTaskPane2.getContentPane().setLayout(jXTaskPane2Layout);
        jXTaskPane2Layout.setHorizontalGroup(
            jXTaskPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPane2Layout.createSequentialGroup()
                .add(jXPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
        );
        jXTaskPane2Layout.setVerticalGroup(
            jXTaskPane2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPane2Layout.createSequentialGroup()
                .add(jXPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXTaskPaneContainer1.add(jXTaskPane2);

        jXPanel3.setBackground(jXTaskPane2.getBackground());

        okJButton.setText("OK");
        okJButton.setEnabled(false);
        okJButton.setPreferredSize(new java.awt.Dimension(81, 23));
        okJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okJButtonActionPerformed(evt);
            }
        });

        cancelJButton.setText("Cancel");
        cancelJButton.setPreferredSize(new java.awt.Dimension(81, 23));
        cancelJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelJButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jXPanel3Layout = new org.jdesktop.layout.GroupLayout(jXPanel3);
        jXPanel3.setLayout(jXPanel3Layout);
        jXPanel3Layout.setHorizontalGroup(
            jXPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jXPanel3Layout.createSequentialGroup()
                .addContainerGap(205, Short.MAX_VALUE)
                .add(okJButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cancelJButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jXPanel3Layout.setVerticalGroup(
            jXPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jXPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cancelJButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(okJButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXTaskPaneContainer1.add(jXPanel3);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPaneContainer1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 406, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jXTaskPaneContainer1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Tries to connect to the database. If successfull the dialog is closed.
     * 
     * @param evt
     */
    private void okJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okJButtonActionPerformed

        this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));

        saveInsertedInformation();

        fragmentationAnalyzer.closeDatabaseConnection();
        boolean connectionError = !fragmentationAnalyzer.connectToDatabase();

        this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        if (!connectionError) {

            fragmentationAnalyzer.getUserProperties().setUserName(fragmentationAnalyzer.getUserProperties().getUserName());
            fragmentationAnalyzer.getUserProperties().setServerHost(fragmentationAnalyzer.getUserProperties().getServerHost());
            fragmentationAnalyzer.getUserProperties().setSchema(fragmentationAnalyzer.getUserProperties().getSchema());
            fragmentationAnalyzer.getUserProperties().saveUserPropertiesToFile();

            if(extractIdentifications){

                boolean folderCreated = new File(fragmentationAnalyzer.getProperties().getCurrentDataSetFolder()).mkdir();

                if (!folderCreated) {
                    JOptionPane.showMessageDialog(this,
                            "An error occured while creating the data set folder.\n" +
                            "See ../Properties/ErrorLog.txt for more details.",
                            "Error Creating Data Set Folder",
                            JOptionPane.ERROR_MESSAGE);
                    Util.writeToErrorLog("Creating Data Set Folder: Error while creating data set folder!");
                } else {
                    dataSourceDialog.extractIdentificationsFromDatabase();
                }
            }

            this.setVisible(false);
            this.dispose();
        }
}//GEN-LAST:event_okJButtonActionPerformed

    /**
     * @see #cancelJButtonActionPerformed(java.awt.event.ActionEvent) 
     *
     * @param evt
     */
    private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
        fragmentationAnalyzer.getProperties().setCurrentDataSetFolder(null);
        this.setVisible(false);
        this.dispose();
}//GEN-LAST:event_cancelJButtonActionPerformed

    /**
     * Checks that all mandatory information is filled in. If 'Enter' is clicked
     * the focus is moved to the password field.
     *
     * @param evt
     */
    private void userNameJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_userNameJTextFieldKeyPressed
        mandatoryFieldsCheck();

        if (okJButton.isEnabled()) {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                passordJPasswordField.requestFocus();
            }
        }
}//GEN-LAST:event_userNameJTextFieldKeyPressed

    /**
     * Checks that all mandatory information is filled in. If 'Enter' is clicked
     * the 'OK' button is automatically activated.
     *
     * @param evt
     */
    private void passordJPasswordFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_passordJPasswordFieldKeyPressed
        mandatoryFieldsCheck();

        if (okJButton.isEnabled()) {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                okJButtonActionPerformed(null);
            }
        }
}//GEN-LAST:event_passordJPasswordFieldKeyPressed

    /**
     * Checks that all mandatory information is filled in. If 'Enter' is clicked
     * the 'OK' button is automatically activated.
     *
     * @param evt
     */
    private void serverHostJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_serverHostJTextFieldKeyPressed
        mandatoryFieldsCheck();

        if (okJButton.isEnabled()) {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                okJButtonActionPerformed(null);
            }
        }
}//GEN-LAST:event_serverHostJTextFieldKeyPressed

    /**
     * Checks that all mandatory information is filled in. If 'Enter' is clicked
     * the 'OK' button is automatically activated.
     *
     * @param evt
     */
    private void schemaJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_schemaJTextFieldKeyPressed
        mandatoryFieldsCheck();

        if (okJButton.isEnabled()) {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                okJButtonActionPerformed(null);
            }
        }
}//GEN-LAST:event_schemaJTextFieldKeyPressed

    /**
     * @see #userNameJTextFieldKeyPressed(java.awt.event.KeyEvent) 
     */
    private void userNameJTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_userNameJTextFieldKeyReleased
        userNameJTextFieldKeyPressed(evt);
    }//GEN-LAST:event_userNameJTextFieldKeyReleased

    /**
     * @see #passordJPasswordFieldKeyPressed(java.awt.event.KeyEvent) 
     */
    private void passordJPasswordFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_passordJPasswordFieldKeyReleased
        passordJPasswordFieldKeyPressed(evt);
    }//GEN-LAST:event_passordJPasswordFieldKeyReleased

    /**
     * @see #serverHostJTextFieldKeyPressed(java.awt.event.KeyEvent)
     */
    private void serverHostJTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_serverHostJTextFieldKeyReleased
        serverHostJTextFieldKeyPressed(evt);
    }//GEN-LAST:event_serverHostJTextFieldKeyReleased

    /**
     * @see #schemaJTextFieldKeyPressed(java.awt.event.KeyEvent)
     */
    private void schemaJTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_schemaJTextFieldKeyReleased
        schemaJTextFieldKeyPressed(evt);
    }//GEN-LAST:event_schemaJTextFieldKeyReleased

    /**
     * Checks if all mandatory information is filled in and enables or disables
     * the OK button.
     */
    private void mandatoryFieldsCheck() {

        if (userNameJTextField.getText().length() > 0 &&
                serverHostJTextField.getText().length() > 0 &&
                schemaJTextField.getText().length() > 0) {
            okJButton.setEnabled(true);
        } else {
            okJButton.setEnabled(false);
        }
    }

    /**
     * Saves the inserted information to the Properties object.
     */
    private void saveInsertedInformation() {
        fragmentationAnalyzer.getUserProperties().setUserName(userNameJTextField.getText());
        fragmentationAnalyzer.getProperties().setPassWord(new String(passordJPasswordField.getPassword()));
        fragmentationAnalyzer.getUserProperties().setServerHost(serverHostJTextField.getText());
        fragmentationAnalyzer.getUserProperties().setSchema(schemaJTextField.getText());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelJButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel3;
    private org.jdesktop.swingx.JXTaskPane jXTaskPane1;
    private org.jdesktop.swingx.JXTaskPane jXTaskPane2;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private javax.swing.JButton okJButton;
    private javax.swing.JPasswordField passordJPasswordField;
    private javax.swing.JTextField schemaJTextField;
    private javax.swing.JTextField serverHostJTextField;
    private javax.swing.JTextField userNameJTextField;
    // End of variables declaration//GEN-END:variables
}
